<template>
  <div>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48" >
            <a-col :md="8" :sm="24">
              <a-form-item label="姓名">
                <a-input v-model="queryParam.user_name" placeholder="请输入姓名"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="手机号">
                <a-input v-model="queryParam.address_phone" placeholder="请输入手机号"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md=" 8 || 24" :sm="24">
              <a-form-item>
                <a-button type="primary" @click="queryTable">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <a-table :columns="columns" :dataSource="dataList" :pagination="false" rowKey="id">
        <a slot="name" slot-scope="text" href="javascript:">{{ text }}</a>
      </a-table>
      <my-pagination
        :total="pagination.totalCount"
        :pageSize="pagination.pageSize"
        :current="pagination.pageNo"
        @onChange="onChangePage"
        @onShowSizeChange="onShowSizeChangePage"
      ></my-pagination>
    </a-card>
  </div>
</template>

<script>
import MyPagination from '../../components/Autism/myPagination'
import { queryUserAddress } from '@/api/userAddress'

const columns = [
  {
    title: '用户昵称',
    dataIndex: 'address_name',
    key: 'address_name'
  },
  {
    title: '手机号',
    dataIndex: 'address_phone',
    key: 'address_phone'
  }, {
    title: '省市区',
    customRender: (text, record) => {
      const address = `${record.province}-${record.city}-${record.area}`
      return address
    }
  }, {
    title: '详细地址',
    key: 'detailed_address',
    dataIndex: 'detailed_address'
  }, {
    title: '创建时间',
    key: 'create_date_time',
    dataIndex: 'create_date_time'
  }
]

export default {
  name: 'UserInfoAddress',
  components: {
    MyPagination
  },
  data: function () {
    return {
      pagination: {
        pageNo: 1,
        pageSize: 10,
        totalCount: 0
      },
      currentTab: 0,
      queryParam: {},
      columns,
      dataList: []
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    // 分页获取列表
    getList: function (isSearch) {
      let param = {
        page_index: this.pagination.pageNo,
        page_size: this.pagination.pageSize
      }
      if (isSearch) {
        param = Object.assign(this.pagination, this.queryParam)
      }
      queryUserAddress(param)
        .then((res) => {
          console.log(res)
          this.dataList = res.collection
          this.pagination.pageNo = res.page_index
          this.pagination.pageSize = res.page_size
          this.pagination.totalCount = res.total_count
        })
        .catch((err) => {
          console.log(err)
        })
    },
    queryTable () {
      this.getList(true)
    },
    onChangePage (pageNo, pageSize) {
      this.pagination.pageNo = pageNo
      // 重新请求数据
      this.getList()
    },
    onShowSizeChangePage (pageNo, pageSize) {
      this.pagination.pageSize = pageSize
      // 重新请求数据
      this.getList()
    }
  }
}
</script>

<style lang="less" scoped>
</style>
